package com.ruoyi.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.constant.IpAddressConstant;
import com.ruoyi.system.domain.HUAWEI.AtLockedItemInfoTi;
import com.ruoyi.system.domain.HUAWEI.AtLockedItemInfoTiRecord;
import com.ruoyi.system.domain.HUAWEI.TBtpMtlCurriculumViateTi;
import com.ruoyi.system.domain.HUAWEI.TBtpMtlCurriculumViateTiDTO;
import com.ruoyi.system.domain.InterfaceLog;
import com.ruoyi.system.domain.Pull.MaterialPlug;
import com.ruoyi.system.domain.WMS.*;
import com.ruoyi.system.domain.base.DataIsolationLockMom;
import com.ruoyi.system.domain.base.DataIsolationLockDTO;
import com.ruoyi.system.domain.MES.OrderInfoUpDTO;
import com.ruoyi.system.domain.base.DataIsolationLockMomDTO;
import com.ruoyi.system.domain.function.ProdOrder;
import com.ruoyi.system.enums.RabbitMqEnum;
import com.ruoyi.system.mapper.DataIsolationLockMomMapper;
import com.ruoyi.system.mapper.HUAWEI.AtLockedItemInfoTiMapper;
import com.ruoyi.system.mapper.HUAWEI.TBtpMtlCurriculumViateTiMapper;
import com.ruoyi.system.mapper.InterfaceLogMapper;
import com.ruoyi.system.mapper.ProdOrderMapper;
import com.ruoyi.system.mapper.WMS.RptInPackageMapper;
import com.ruoyi.system.mapper.pull.MaterialPlugMapper;
import com.ruoyi.system.service.WMSService;
import com.ruoyi.system.utils.rabbitMq.direct.DirectSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @description:
 * @author: zhengxiong.jiang
 * @createDate: 2023/3/3
 * @version: 1.0
 */
@Service
@Component("wmsTask")
//每次请求多创建一个bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class WMSServiceImpl implements WMSService {

    @Autowired
    private InterfaceLogMapper interfaceLogMapper;
    @Autowired
    private MaterialPlugMapper materialPlugMapper;
    @Autowired
    private TBtpMtlCurriculumViateTiMapper tiMapper;
    @Autowired
    private DataIsolationLockMomMapper dataIsolationLockMomMapper;
    @Autowired
    private AtLockedItemInfoTiMapper atLockedItemInfoTiMapper;
    @Autowired
    private DirectSender myProducer;
    @Autowired
    private RptInPackageMapper rptInPackageMapper;
    @Autowired
    private ProdOrderMapper prodOrderMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String materialFeedback(List<TBtpMtlCurriculumViateTiDTO> dto) {
        if(IterUtil.isEmpty(dto)){
            throw new CustomException("接收物料反馈数据为空");
        }
        //日志记录
        InterfaceLog interfaceLog = new InterfaceLog();
        interfaceLog.setSerialNumber(String.valueOf(new Date().getTime()));
        interfaceLog.setStartTime(new Date());
        interfaceLog.setInterfaceDirection("WMS->MOM");
        interfaceLog.setPacketSize("");
        interfaceLog.setInterfaceRequest(JSONUtil.toJsonStr(dto));
        interfaceLog.setEndTime(new Date());
        interfaceLog.setInterfaceResponse("WMS接收成功");
        long be = DateUtil.between(interfaceLog.getStartTime(), interfaceLog.getEndTime(), DateUnit.MS);
        interfaceLog.setTimeConsuming(String.valueOf(be));
        interfaceLog.setCreateTime(new Date());
        interfaceLog.setInterfaceType("http");
        interfaceLog.setInterfaceName("物料反馈");
        interfaceLogMapper.insert(interfaceLog);

        dto.stream().forEach(i->{
            //根据wms返回字段更新补料记录  todo 后续新增功能****更新我们自己库存记录
//            MaterialPlug materialPlug = new MaterialPlug(i);
//            materialPlugMapper.update(materialPlug,new QueryWrapper<MaterialPlug>().eq("plug_numbers",materialPlug.getPlugNumbers()));
            //WMS的投料信息需回传MOM作为后续物料履历数据传给华为
            TBtpMtlCurriculumViateTi ti = new TBtpMtlCurriculumViateTi();
            //通过补料单号找到任务令回传华为*****
            BeanUtil.copyProperties(i,ti);
            TBtpMtlCurriculumViateTi tB = tiMapper.selectOne(new QueryWrapper<TBtpMtlCurriculumViateTi>().eq("source_key_id", i.getSourceKeyId()));
            if(ObjectUtil.isNotNull(tB)){
//                throw new CustomException(i.getSourceKeyId()+"数据已存在");
                tiMapper.update(ti,new QueryWrapper<TBtpMtlCurriculumViateTi>().eq("source_key_id", i.getSourceKeyId()));
            }else {
                tiMapper.insert(ti);
            }
        });
        return "接收成功";
    }

    @Override
    public AjaxResult materialIssued(List<Long> plugIds) {
        for (int i = 0; i < plugIds.size(); i++) {
            List<RefuelingOrderDTO> list = new ArrayList<>();
            MaterialPlug materialPlug = materialPlugMapper.selectById(plugIds.get(i));
            if(materialPlug.getStatus()==1){
                return AjaxResult.error("此补料单已经下发，请勿重复下发！");
            }
            RefuelingOrderDTO refuelingOrderDTO = new RefuelingOrderDTO(materialPlug);

            LoginUser loginUser = SecurityUtils.getLoginUser();
            refuelingOrderDTO.setServiceid(String.valueOf(loginUser.getUser().getDeptId()));
            refuelingOrderDTO.setCreateman(loginUser.getUser().getUserName());
            refuelingOrderDTO.setStates("");
            refuelingOrderDTO.setSeq(1+plugIds.get(i));
            refuelingOrderDTO.setAuditdate(DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
            refuelingOrderDTO.setAuditman(String.valueOf(loginUser.getUser().getUserId()));
            refuelingOrderDTO.setAuditmanname(SecurityUtils.getUsername());
            refuelingOrderDTO.setCreatemanid(String.valueOf(loginUser.getUser().getUserId()));
            refuelingOrderDTO.setSubmitman(SecurityUtils.getUsername());
            refuelingOrderDTO.setSubmitdate(DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));


            RefuelingOrderLines refuelingOrderLines = new RefuelingOrderLines(materialPlug);
            refuelingOrderLines.setWorkshopid("0"+materialPlug.getDeptId());//这个后续要改暂时写死,根据产线往上找到车间
            refuelingOrderLines.setWorkcenterid("WM-01");
            refuelingOrderLines.setStockid("");//仓库仓位理论上从mes拿
            refuelingOrderLines.setLocationid("");
            refuelingOrderLines.setStationid(materialPlug.getStationCode());
            refuelingOrderLines.setMaterielid(materialPlug.getMaterialCode());
            refuelingOrderLines.setBegindate(DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
            refuelingOrderLines.setFreedom1(materialPlug.getTaskTon());
            refuelingOrderLines.setFreedom2(materialPlug.getProductCode());


            List<RefuelingOrderLines> listre = new ArrayList<>();
            listre.add(refuelingOrderLines);
            for (int j = 0; j < listre.size(); j++) {
                listre.get(j).setSequence(j+1);
            }

            refuelingOrderDTO.setRefuelingOrderLines(listre);
            list.add(refuelingOrderDTO);

            String response= HttpUtil.post(IpAddressConstant.WMS_IP+"/api/app/default-materiel-demand/materiel-demand-orders", JSONUtil.toJsonStr(list));

            //日志记录
            InterfaceLog interfaceLog = new InterfaceLog();
            interfaceLog.setSerialNumber(String.valueOf(new Date().getTime()));
            interfaceLog.setStartTime(new Date());
            interfaceLog.setInterfaceDirection("MOM->WMS");
            interfaceLog.setPacketSize("");
            interfaceLog.setInterfaceRequest(JSONUtil.toJsonStr(list));
            interfaceLog.setEndTime(new Date());
            interfaceLog.setInterfaceResponse(response);
            long be = DateUtil.between(interfaceLog.getStartTime(), interfaceLog.getEndTime(), DateUnit.MS);
            interfaceLog.setTimeConsuming(String.valueOf(be));
            interfaceLog.setCreateBy(SecurityUtils.getUsername());
            interfaceLog.setCreateTime(new Date());
            interfaceLog.setInterfaceType("http");
            interfaceLog.setInterfaceName("补料下发");
            interfaceLogMapper.insert(interfaceLog);


            //下发成功修改状态
            MaterialPlug mat = new MaterialPlug();
            mat.setStatus(1);
            materialPlugMapper.update(mat,new QueryWrapper<MaterialPlug>().eq("plug_id",plugIds.get(i)));
        }
        return AjaxResult.success("下发成功");
    }


    @Override
    public String lock(List<Integer> pkids) {
        if(IterUtil.isEmpty(pkids)){
            throw new CustomException("隔离主键id不能为空");
        }
        List<DataIsolationLockDTO> dtos = new ArrayList<>();
        pkids.stream().forEach(i->{
            DataIsolationLockMom dataIsolationLockMom = dataIsolationLockMomMapper.selectById(i);
            DataIsolationLockDTO dto = new DataIsolationLockDTO();
            BeanUtil.copyProperties(dataIsolationLockMom,dto);

            if(dataIsolationLockMom.getCreatedDate()!=null){
                dto.setCreatedDate(DateUtil.format(dataIsolationLockMom.getCreatedDate(),"yyyy-MM-dd HH:mm:ss"));
                dto.setCreateTime(DateUtil.format(dataIsolationLockMom.getCreatedDate(),"yyyy-MM-dd HH:mm:ss"));
            }

            if(dataIsolationLockMom.getUpdatedDate()!=null){
                dto.setUpdatedDate(DateUtil.format(dataIsolationLockMom.getUpdatedDate(),"yyyy-MM-dd HH:mm:ss"));
            }
            if(dataIsolationLockMom.getSyncStatus()!=null){
                dto.setSyncStatus(String.valueOf(dataIsolationLockMom.getSyncStatus()));
            }
            dtos.add(dto);
        });

        //请求WMS锁定接口
        String response= HttpUtil.post(IpAddressConstant.WMS_IP+"/api/app/default-data-isolation/data-isolation-lock", JSONUtil.toJsonStr(dtos));

        Map map = JSONUtil.toBean(response, Map.class);
        boolean rtnSuccess = (boolean)map.get("rtnSuccess");
        if(rtnSuccess){
            JSONArray array = JSONUtil.parseArray(JSONUtil.toJsonStr(map.get("dynamicDto")));
            List<DataIsolationLockDTO> dtoList = JSONUtil.toList(array, DataIsolationLockDTO.class);
            if(IterUtil.isNotEmpty(dtoList)){
                dtoList.stream().forEach(dto -> {
                    DataIsolationLockMom data = new DataIsolationLockMom();
                    AtLockedItemInfoTi at = atLockedItemInfoTiMapper.selectOne(new QueryWrapper<AtLockedItemInfoTi>().eq("trans_id", dto.getTransId()));
                    BeanUtil.copyProperties(at,data);
                    if("NVL".equals(at.getBar09()) && "NVL".equals(at.getPsn()) && "NVL".equals(at.getBarcode())){
                        List<BarcodeDtos> dtosLs = dto.getBarcodeDtos();
                        if(IterUtil.isNotEmpty(dtosLs)){
                            String psn = "";
                            String bar09 = "";
                            String barcode = "";
                            for (int i = 0; i < dtosLs.size(); i++) {
                                if(StrUtil.isNotEmpty(dtosLs.get(i).getPsn())){
                                    psn+=dtosLs.get(i).getPsn()+",";
                                }

                                if(StrUtil.isNotEmpty(dtosLs.get(i).getBar09())){
                                    bar09+=dtosLs.get(i).getBar09()+",";
                                }

                                if(StrUtil.isNotEmpty(dtosLs.get(i).getBarcode())){
                                    barcode+=dtosLs.get(i).getBarcode()+",";
                                }
                            }
                            data.setPsn(psn);
                            data.setBar09(bar09);
                            data.setBarcode(barcode);
                        }
                    }
                    //进行本地隔离单数据存储更新
                    DataIsolationLockMom da = dataIsolationLockMomMapper.selectOne(new QueryWrapper<DataIsolationLockMom>().eq("trans_id", dto.getTransId()));
                    if(ObjectUtil.isNotNull(da)){
                        data.setHaweiAndMom(1);
                        dataIsolationLockMomMapper.update(data,new QueryWrapper<DataIsolationLockMom>().eq("trans_id",dto.getTransId()));
                    }else {
                        dataIsolationLockMomMapper.insert(data);
                    }
                    // todo 下发至MES
                    //下发至MES
                    this.sendMesGl(data);

                });
            }
            return "操作成功";
        }else {
            //错误日志记录
            InterfaceLog interfaceLog = new InterfaceLog();
            interfaceLog.setSerialNumber(String.valueOf(new Date().getTime()));
            interfaceLog.setStartTime(new Date());
            interfaceLog.setInterfaceDirection("MOM->WMS");
            interfaceLog.setPacketSize("");
            interfaceLog.setInterfaceRequest(JSONUtil.toJsonStr(dtos));
            interfaceLog.setEndTime(new Date());
            interfaceLog.setInterfaceResponse(response);
            long be = DateUtil.between(interfaceLog.getStartTime(), interfaceLog.getEndTime(), DateUnit.MS);
            interfaceLog.setTimeConsuming(String.valueOf(be));
            interfaceLog.setCreateBy("admin");
            interfaceLog.setCreateTime(new Date());
            interfaceLog.setInterfaceType("http");
            interfaceLog.setInterfaceName("华为隔离单同步");
            interfaceLogMapper.insert(interfaceLog);
            String rtnMsg = (String)map.get("rtnMsg");
            return "隔离单同步失败："+rtnMsg;
        }

    }

    @Override
    @Async("asyncExecutor")
//    @Async
    public void gldSync() {
        System.out.println("=====================隔离同步下发至WMS与MES开始================================");
        List<DataIsolationLockDTO> dtos = new ArrayList<>();
        List<AtLockedItemInfoTiRecord> list = atLockedItemInfoTiMapper.selectDistinRecord();
        // todo 测试先注释后续放开  下面这个删除 2023-09-26 15:54:06
//        List<AtLockedItemInfoTi> list = atLockedItemInfoTiMapper.selectDistin();
//        List<AtLockedItemInfoTiRecord> list = atLockedItemInfoTiMapper.selectDistinPc();


        if(IterUtil.isNotEmpty(list)){

            for (int i = 0; i < list.size(); i++) {
                DataIsolationLockDTO dto = new DataIsolationLockDTO();
                BeanUtil.copyProperties(list.get(i),dto);
                if(list.get(i).getCreatedDate()!=null){
                    dto.setCreatedDate(DateUtil.format(list.get(i).getCreatedDate(),"yyyy-MM-dd HH:mm:ss"));
                }
                if(list.get(i).getCreateTime()!=null){
                    dto.setCreateTime(DateUtil.format(list.get(i).getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
                }
                if(list.get(i).getUpdatedDate()!=null){
                    dto.setUpdatedDate(DateUtil.format(list.get(i).getUpdatedDate(),"yyyy-MM-dd HH:mm:ss"));
                }
                if(list.get(i).getSyncStatus()!=null){
                    dto.setSyncStatus(String.valueOf(list.get(i).getSyncStatus()));
                }
                dtos.add(dto);
            }


//            list.stream().forEach(i->{
//                DataIsolationLockDTO dto = new DataIsolationLockDTO();
//                BeanUtil.copyProperties(i,dto);
//                if(i.getCreatedDate()!=null){
//                    dto.setCreatedDate(DateUtil.format(i.getCreatedDate(),"yyyy-MM-dd HH:mm:ss"));
//                }
//                if(i.getCreateTime()!=null){
//                    dto.setCreateTime(DateUtil.format(i.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
//                }
//                if(i.getUpdatedDate()!=null){
//                    dto.setUpdatedDate(DateUtil.format(i.getUpdatedDate(),"yyyy-MM-dd HH:mm:ss"));
//                }
//                if(i.getSyncStatus()!=null){
//                    dto.setSyncStatus(String.valueOf(i.getSyncStatus()));
//                }
//                dtos.add(dto);
//            });

            //请求WMS锁定接口
            String response= HttpUtil.post(IpAddressConstant.WMS_IP+"/api/app/default-data-isolation/data-isolation-lock", JSONUtil.toJsonStr(dtos));

            Map map = JSONUtil.toBean(response, Map.class);
            boolean rtnSuccess = (boolean)map.get("rtnSuccess");
            if(rtnSuccess){
                JSONArray array = JSONUtil.parseArray(JSONUtil.toJsonStr(map.get("dynamicDto")));
                List<DataIsolationLockDTO> dtoList = JSONUtil.toList(array, DataIsolationLockDTO.class);
                if(IterUtil.isNotEmpty(dtoList)){
                    dtoList.stream().forEach(dto -> {
                        DataIsolationLockMom data = new DataIsolationLockMom();
                        List<AtLockedItemInfoTi> at = atLockedItemInfoTiMapper.selectList(new QueryWrapper<AtLockedItemInfoTi>().eq("trans_id", dto.getTransId()).orderByDesc("updated_date"));
                        BeanUtil.copyProperties(at.get(0),data);
                        if(("NVL".equals(at.get(0).getBar09()) || at.get(0).getBar09() ==null)
                                && ("NVL".equals(at.get(0).getPsn())||at.get(0).getPsn()==null)
                                && ("NVL".equals(at.get(0).getBarcode())||at.get(0).getPsn()==null)){
                            List<BarcodeDtos> dtosLs = dto.getBarcodeDtos();
                            if(IterUtil.isNotEmpty(dtosLs)){
                                String psn = "";
                                String bar09 = "";
                                String barcode = "";
                                for (int i = 0; i < dtosLs.size(); i++) {
                                    if(StrUtil.isNotEmpty(dtosLs.get(i).getPsn())){
                                        psn+=dtosLs.get(i).getPsn()+",";
                                    }

                                    if(StrUtil.isNotEmpty(dtosLs.get(i).getBar09())){
                                        bar09+=dtosLs.get(i).getBar09()+",";
                                    }

                                    if(StrUtil.isNotEmpty(dtosLs.get(i).getBarcode())){
                                        barcode+=dtosLs.get(i).getBarcode()+",";
                                    }
                                }
                                data.setPsn(psn);
                                data.setBar09(bar09);
                                data.setBarcode(barcode);
                            }

                        }
                        //下发产线mes
                        this.sendMesGl(data);
                        //触发器生成表更新
                        atLockedItemInfoTiMapper.updateByRecord(data.getTransId(),DateUtil.format(data.getUpdatedDate(),"yyyy-MM-dd HH:mm:ss"));
//                        atLockedItemInfoTiMapper.deleteByRecord(data.getTransId());

                        //进行本地隔离单数据存储更新
                        DataIsolationLockMom da = dataIsolationLockMomMapper.selectOne(new QueryWrapper<DataIsolationLockMom>().eq("trans_id", dto.getTransId()));
                        if(ObjectUtil.isNotNull(da)){
                            data.setHaweiAndMom(1);
                            data.setUpdatedDate(new Date());
                            dataIsolationLockMomMapper.update(data,new QueryWrapper<DataIsolationLockMom>().eq("trans_id",dto.getTransId()));
                        }else {
                            dataIsolationLockMomMapper.insert(data);
                        }




                    });
                }
            }else {
                //错误日志记录
                InterfaceLog interfaceLog = new InterfaceLog();
                interfaceLog.setSerialNumber(String.valueOf(new Date().getTime()));
                interfaceLog.setStartTime(new Date());
                interfaceLog.setInterfaceDirection("MOM->WMS");
                interfaceLog.setPacketSize("");
                interfaceLog.setInterfaceRequest(JSONUtil.toJsonStr(dtos));
                interfaceLog.setEndTime(new Date());
                interfaceLog.setInterfaceResponse(response);
                long be = DateUtil.between(interfaceLog.getStartTime(), interfaceLog.getEndTime(), DateUnit.MS);
                interfaceLog.setTimeConsuming(String.valueOf(be));
                interfaceLog.setCreateBy("admin");
                interfaceLog.setCreateTime(new Date());
                interfaceLog.setInterfaceType("http");
                interfaceLog.setInterfaceName("华为隔离单同步");
                interfaceLogMapper.insert(interfaceLog);
//                String rtnMsg = (String)map.get("rtnMsg");
            }
        }
        System.out.println("=====================隔离同步下发至WMS与MES结束================================");
    }

    @Override
    public String sedPackage(List<RptInPackageDTO> dto) {
        //根据工单号查询出计划编号
        if(IterUtil.isNotEmpty(dto)){
            dto.stream().forEach(j->{
                String fPlanNo = j.getManubillno();
                ProdOrder prodOrder = prodOrderMapper.selectOne(new QueryWrapper<ProdOrder>().eq("order_code", fPlanNo));
                j.setFPlanJhNo(prodOrder.getPlanCode());
                j.setTaskTon(prodOrder.getTaskTon());
            });
        }


        //mes包装信息接口
        String response= HttpUtil.post(IpAddressConstant.WMS_IP+"/api/app/default-default-rpt-in-package/ins-rpt-in-package", JSONUtil.toJsonStr(dto));
        Map map = JSONUtil.toBean(response, Map.class);
        boolean rtnSuccess = (boolean)map.get("rtnSuccess");
        //本地包装数据存储
        if(IterUtil.isNotEmpty(dto)){
            dto.stream().forEach(i->{
                RptInPackage rptInPackage = new RptInPackage();
                BeanUtil.copyProperties(i,rptInPackage);
                rptInPackage.setCreatedate(DateUtil.parse(i.getCreatedate(),"yyyy-MM-dd HH:mm:ss"));
//                rptInPackage.setCreatedate(i.getCreatedate());
                rptInPackage.setPackageSerialNos(JSONUtil.toJsonStr(i.getPackageSerialNos()));
                if(rtnSuccess){
                    rptInPackage.setRes("请求成功");
                    rptInPackageMapper.insert(rptInPackage);
                }else {
                    rptInPackage.setRes("请求失败："+(String) map.get("rtnMsg"));
                    rptInPackageMapper.insert(rptInPackage);
                }
            });
        }
        if(rtnSuccess){
            return "请求成功";
        }else {
            return "请求失败："+(String) map.get("rtnMsg");
        }

    }

    /**
     * 隔离数据下发至Mes
     * @param data
     */
    private void sendMesGl(DataIsolationLockMom data) {
        DataIsolationLockMomDTO dto = new DataIsolationLockMomDTO();
        BeanUtil.copyProperties(data,dto);
        if(data.getCreatedDate()!=null){
            dto.setCreatedDate(DateUtil.format(data.getCreatedDate(),"yyyy-MM-dd HH:mm:ss"));
        }
        if(data.getUpdatedDate()!=null){
            dto.setUpdatedDate(DateUtil.format(data.getUpdatedDate(),"yyyy-MM-dd HH:mm:ss"));
        }

        //下发日志记录
        InterfaceLog interfaceLog = new InterfaceLog();
        interfaceLog.setSerialNumber(String.valueOf(new Date().getTime()));
        interfaceLog.setStartTime(new Date());
        interfaceLog.setInterfaceDirection("MOM->MES");
        interfaceLog.setPacketSize("");

        //封装发送队列数据
        OrderInfoUpDTO orderInfoUpDTO = new OrderInfoUpDTO();
        orderInfoUpDTO.setInterface("LOCKED_ITEM");
        String bar09 = dto.getBar09();
        String barcode = dto.getBarcode();
        String psn = dto.getPsn();

        if(StrUtil.isNotEmpty(bar09)&&!"NVL".equals(bar09)){
            List<String> collect = Arrays.stream(bar09.split(",")).collect(Collectors.toList());
            for (String st:collect){
                dto.setBar09(st);
                orderInfoUpDTO.setBody(dto);
                // todo 改为接口方式传输
//                myProducer.send(RabbitMqEnum.LOCKED_ITEM.getCode(),JSONUtil.toJsonStr(orderInfoUpDTO));
                //发送隔离数据至mes
                String response= HttpUtil.post(IpAddressConstant.MES_IP01+"/api/services/app/QM_ProductPartsDetail/AT_LOCKED_INFO", JSONUtil.toJsonStr(orderInfoUpDTO));

            }
        }

        if(StrUtil.isNotEmpty(barcode)&&!"NVL".equals(barcode)){
            List<String> collect = Arrays.stream(barcode.split(",")).collect(Collectors.toList());
            for (String st:collect){
                dto.setBarcode(st);
                orderInfoUpDTO.setBody(dto);
//                myProducer.send(RabbitMqEnum.LOCKED_ITEM.getCode(),JSONUtil.toJsonStr(orderInfoUpDTO));
                //发送隔离数据至mes
                String response= HttpUtil.post(IpAddressConstant.MES_IP01+"/api/services/app/QM_ProductPartsDetail/AT_LOCKED_INFO", JSONUtil.toJsonStr(orderInfoUpDTO));
            }
        }

        if(StrUtil.isNotEmpty(psn)&&!"NVL".equals(psn)){
            List<String> collect = Arrays.stream(psn.split(",")).collect(Collectors.toList());
            for (String st:collect){
                dto.setPsn(st);
                orderInfoUpDTO.setBody(dto);
//                myProducer.send(RabbitMqEnum.LOCKED_ITEM.getCode(),JSONUtil.toJsonStr(orderInfoUpDTO));
                //发送隔离数据至mes
                String response= HttpUtil.post(IpAddressConstant.MES_IP01+"/api/services/app/QM_ProductPartsDetail/AT_LOCKED_INFO", JSONUtil.toJsonStr(orderInfoUpDTO));
            }
        }

        interfaceLog.setInterfaceRequest(JSONUtil.toJsonStr(orderInfoUpDTO));
        interfaceLog.setInterfaceName("下发隔离单数据至Mes");
        interfaceLog.setEndTime(new Date());
        interfaceLog.setInterfaceResponse("隔离数据下发至Mes成功");
        long be = DateUtil.between(interfaceLog.getStartTime(), interfaceLog.getEndTime(), DateUnit.MS);
        interfaceLog.setTimeConsuming(String.valueOf(be));
        interfaceLog.setCreateBy("admin");
        interfaceLog.setCreateTime(new Date());
        interfaceLog.setInterfaceType("http");
        interfaceLogMapper.insert(interfaceLog);

    }


}
